import java.util.Scanner;
/*
005300000
800000020
070010500
400005300
010070006
003200080
060500009
004000030
000009700
*/
public class Sudoku {
    private static int[][] board = new int[9][9];
    private static int id = 0;
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < 9; i++) {
            String line = input.nextLine();
            for (int j = 0; j < line.length(); j++) {
                board[i][j] = line.charAt(j) - '0';
            }
        }
        solve(0, 0);
    }

    private static void solve(int row, int col) {
        if (row == 9) {
            id++;
            System.out.println("第" + id + "种解：");
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    System.out.print(board[i][j] + " ");
                }
                System.out.println();
            }
        } else {
            if (board[row][col] == 0) {
                for (int num = 1; num <= 9; num++) {
                    if (check(row, col, num)) {
                        board[row][col] = num;
                        solve(row + (col + 1) / 9, (col + 1) % 9);
                        board[row][col] = 0; // ?
                    }
                }
            } else {
                solve(row + (col + 1) / 9, (col + 1) % 9);
            }
        }
    }

    private static boolean check(int row, int col, int num) {
        //同行
        for (int c = 0; c < 9; c++) {
            if (board[row][c] == num) {
                return false;
            }
        }
        //同列
        for (int r = 0; r < 9; r++) {
            if (board[r][col] == num) {
                return false;
            }
        }

        //同粗线宫
        int rowMin = 0;
        int rowMax = 0;
        int colMin = 0;
        int colMax = 0;
        if (row >= 0 && row <= 2) {
            rowMin = 0;
            rowMax = 2;
        }
        if (row >= 3 && row <= 5) {
            rowMin = 3;
            rowMax = 5;
        }
        if (row >= 6 && row <= 8) {
            rowMin = 6;
            rowMax = 8;
        }
        if (col >= 0 && col <= 2) {
            colMin = 0;
            colMax = 2;
        }
        if (col >= 3 && col <= 5) {
            colMin = 3;
            colMax = 5;
        }
        if (col >= 6 && col <= 8) {
            colMin = 6;
            colMax = 8;
        }
        for (int i = rowMin; i <= rowMax; i++) {
            for (int j = colMin; j <= colMax; j++) {
                if (board[i][j] == num) {
                    return false;
                }
            }
        }
        return true;
    }
}